package com.forhappy.light3ds8.datatype;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;

public class DataReal {
	public static int IDX_ID = 1;
	public static int IDX_DATAS = 2;
	public int id;
	public String datas;
	public ContentValues toContentValue(){
		ContentValues value = new ContentValues();
		value.put("id", id);
		value.put("datas", datas);
		return value;
	}
	public String toJsonStr(){
		JSONObject js = new JSONObject();
		try {
			js.put("id", id);
			js.put("datas", datas);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return js.toString();
	}

	public DataReal() {

	}
	public DataReal(JSONObject js) {
		try {
			if(js.has("id")){
				id = js.getInt("id");
			}
			datas = js.getString("datas");
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	@Override
	public String toString() {
		return toJsonStr();
	}

	public static LinkedList<DataReal> getDatas(ResultSet rs){
		LinkedList<DataReal> loadDatas = new LinkedList<DataReal>();
		if(null == rs){
			return loadDatas;
		}

		try {
			while(rs.next()){
				DataReal data = new DataReal();
				data.id = rs.getInt(IDX_ID);
				data.datas = rs.getString(IDX_DATAS);
				loadDatas.add(data);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return loadDatas;
	}

}
